package com.enjoyor.soa.traffic.core.efoms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.efoms.domain.PingConnectHis;
import com.enjoyor.soa.traffic.core.efoms.mapper.IPingConnectHisMapper;
import com.enjoyor.soa.traffic.core.efoms.service.IPingConnectHisService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.LoggerHelper;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;

@Service
@Transactional
public class PingConnectHisService implements IPingConnectHisService {

    @Autowired
    private IPingConnectHisMapper pingConnectHisMapper;

    @Autowired
    private IPubLogMapper pubLogMapper;

    @Override
    public PingConnectHis selectPingConnectHisById(String pingHisId){
        return pingConnectHisMapper.selectById(pingHisId);
    }
    
    @Override
	public List<PingConnectHis> selectPingConnectHisList(String pingHisId, String devCategoryCode,
			String devTypeCode, String devId, String devName, String creatStartTime, String creatEndTime) {
    	try {
	    	Map<String,Object> paramT = new HashMap<String ,Object>();
	    	paramT.put("pingHisId", pingHisId);
	    	paramT.put("devCategoryCode", devCategoryCode);
	    	paramT.put("devTypeCode", devTypeCode);
	    	paramT.put("devId", devId);
	    	paramT.put("devName", devName);
	    	paramT.put("creatStartTime", creatStartTime);
	    	paramT.put("creatEndTime", creatEndTime);
	    	return pingConnectHisMapper.selectPingConnectHisList(paramT);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    public String insertPingConnectHis(PingConnectHis pingConnectHis, String personName){
    	try {
	    	// 默认操作记录信息
	        String pingHisId = "PH" + TimeHelper.getUniqueString();
	        pingConnectHis.setPingHisId(pingHisId);
	        pingConnectHis.setCreatTime(TimeHelper.dateToLongString());
	        pingConnectHisMapper.insert(pingConnectHis);
	    	
	        pubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
	                String.format("添加网络历史编号:{%s} 操作成功!", new Object[] { pingHisId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_MONITOR_MANAGEMENT.getMessage());
	        return pingHisId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }

    @Override
    public String updatePingConnectHis(PingConnectHis pingConnectHis, String personName){
    	try {
	    	String pingHisId = pingConnectHis.getPingHisId();
	    	//pingConnectHis.setCreatTime(TimeHelper.dateToLongString());
	        pingConnectHisMapper.updateByIdSelective(pingConnectHis);
	        pubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
	                String.format("修改网络历史编号:{%s} 操作成功!", new Object[] { pingHisId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_MONITOR_MANAGEMENT.getMessage());
	        return pingHisId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }

    @Override
    public String deletePingConnectHis(String pingHisId, String personName){
    	try {
    		pingConnectHisMapper.deleteById(pingHisId);
	        pubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
	                String.format("删除网络历史编号:{%s} 操作成功!", new Object[] { pingHisId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_MONITOR_MANAGEMENT.getMessage());
	        return pingHisId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
}
